package engine.parser;

import engine.parser.exceptions.NameUnavailableException;
import engine.parser.exceptions.ValueUnavailableException;

public class Token
{
	private TokenKind kind;
	private double value;
	private String name;
	
	public Token(TokenKind kind, double value)
	{
		this.kind = kind;
		this.value = value;
	}
	
	public Token(TokenKind kind, String name)
	{
		this.kind = kind;
		this.name = name;
	}
	
	public Token(TokenKind kind)
	{
		this.kind = kind;
	}
	
	public TokenKind getKind()
	{
		return kind;
	}
	
	public double getValue()
	{
		if(kind != TokenKind.Number) throw new ValueUnavailableException();
		
		return value;
	}
	
	public String getName()
	{
		if(kind != TokenKind.Name) throw new NameUnavailableException();
		
		return name;
	}
	
	public String toString()
	{
		if(kind == TokenKind.Number) return "["+kind+";"+value+"]";
		if(kind == TokenKind.Name) return "["+kind+";"+name+"]";
		return "["+kind+"]";
	}
}
